
R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin17.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> ##########################################################################################################
> #Replication Files for Housing Discrimination and the Toxics Exposure Gap in the United States: 
> #Evidence from the Rental Market  by Peter Christensen, Ignacio Sarmiento-Barbieri and Christopher Timmins
> ##########################################################################################################
> 
> #Clean the workspace
> rm(list=ls())
> cat("\014")
> local({r <- getOption("repos"); r["CRAN"] <- "http://cran.r-project.org"; options(repos=r)}) #set repo
> 
> 
> #Load Packages
> pkg<-c("dplyr","rgdal","ggmap","maps","ggthemes")
> lapply(pkg, require, character.only=T)
Loading required package: dplyr

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Loading required package: rgdal
Loading required package: sp
rgdal: version: 1.5-12, (SVN revision 1018)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.4.2, released 2019/06/28
Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgdal/gdal
GDAL binary built with GEOS: FALSE 
Loaded PROJ runtime: Rel. 5.2.0, September 15th, 2018, [PJ_VERSION: 520]
Path to PROJ shared files: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgdal/proj
Linking to sp version:1.4-2
Overwritten PROJ_LIB was /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgdal/proj
Loading required package: ggmap
Loading required package: ggplot2
Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
Please cite ggmap if you use it! See citation("ggmap") for details.
Loading required package: maps
Loading required package: ggthemes
[[1]]
[1] TRUE

[[2]]
[1] TRUE

[[3]]
[1] TRUE

[[4]]
[1] TRUE

[[5]]
[1] TRUE

> rm(pkg)
> 
> # load data sets ----------------------------------------------------------
> dta<-read.csv("../stores/Potential_zips.csv")
> 
> zip<-rgdal::readOGR("../stores/zipcodes/cb_2017_us_zcta510_500k.shp", layer="cb_2017_us_zcta510_500k")
OGR data source with driver: ESRI Shapefile 
Source: "/Users/iggy/Dropbox/Research/Toxic_Discrimination/github/Toxic_Discrimination/stores/zipcodes/cb_2017_us_zcta510_500k.shp", layer: "cb_2017_us_zcta510_500k"
with 33144 features
It has 5 fields
Integer64 fields read as strings:  ALAND10 AWATER10 
> zip@data<-zip@data %>% mutate_all(as.character)
> zip@data<-data.frame(zip@data)
> 
> 
> zip_subset<-zip[zip@data$ZCTA5CE10%in%dta$zipcodes,]
> zip_subset<-spTransform(zip_subset,CRS=CRS("+proj=longlat +datum=WGS84"))
> 
> 
> us_states <- map_data("state")
> 
> 
> ggplot(data = us_states, mapping = aes(x = long, y = lat, group = group)) +
+   geom_polygon(color = "gray48", fill="white", size = 0.2) +
+   coord_map(projection = "albers", lat0 = 39, lat1 = 45)  +
+   geom_polygon(data=zip_subset, aes(x=long, y=lat, group=group), color="black", alpha=1) +
+   theme_map() +
+   theme(plot.margin=grid::unit(c(0,0,0,0), "cm"), 
+         #legend.justification=c(.95,.95), 
+         legend.position="right",#c(.95,.95), 
+         legend.key = element_rect(fill = "white"),
+         text = element_text(size=10),
+         axis.title.x=element_blank(),
+         axis.text.x=element_blank(),
+         axis.ticks.x=element_blank(),
+         axis.title.y=element_blank(),
+         axis.text.y=element_blank(),
+         axis.ticks.y=element_blank()) 
Regions defined for each Polygons
> ggsave("../views/fig1a.pdf")
Saving 7 x 7 in image
> 
> 
> 
> proc.time()
   user  system elapsed 
  6.613   0.628   7.327 
